package com.example.demo.services.impl;

import com.example.demo.domain.vo.BorrowVO;
import com.example.demo.exception.MyException;
import com.example.demo.mapper.BorrowMapper;
import com.example.demo.services.BorrowServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import cn.hutool.core.collection.CollUtil;

import java.util.List;
@Service
public class BorrowServicesImpl implements BorrowServices {
    @Autowired
    BorrowMapper borrowMapper;

    @Override
    public List<BorrowVO> listAllBorrowList() {
        List<BorrowVO> allRecords = borrowMapper.listAllBorrowedList();
        if(CollUtil.isEmpty(allRecords)){
            throw new MyException("没有借阅的书籍信息！");
        }
        return allRecords;
    }

    @Override
    public List<BorrowVO> listAllBorrowByUserId(int id) {
        List<BorrowVO> records = borrowMapper.listAllBorrowedByUser(id);
        if(CollUtil.isEmpty(records)){
            throw new MyException("没有借阅的书籍信息！");
        }
        return records;
    }
}
